use log::{debug, info};
use crate::mysql_demo::mysql_demo_query::mysql_conn_test;
use crate::mysql_query::mysql::try_conn;

use mysql::prelude::*;
use mysql::*;
use crate::config::{get_jdbc_url, init_config};

mod logs;
mod printonlywarn;
mod mysql_query;
mod mysql_demo;
mod config;
mod r#const;

fn main() {
    // init
    // 使用 log4rs::init_file 方法读取配置文件进行初始化
    log4rs::init_file("log4rs.yaml", Default::default()).unwrap();
    init_config();

    // 获取 mysql conn
    let url = get_jdbc_url();
    let mut conn: PooledConn = try_conn(&url);


    info!(target:"", "################ main ###################");
    // 执行查询语句
    let query_sql = String::from("Select * from time_zone_transition \
                            order by Transition_type_id limit 2");
    debug!("query sql:{}.", &query_sql);
    // 流式查询  数据逐行读取，数据不会存储在内存中
    conn.query_iter(query_sql)
        .unwrap()
        .for_each(|row| {
            let r: (i32, String, i32) = from_row(row.unwrap());
            println!(
                "STREAM: Time_zone_id={},Transition_time={},Transition_type_id={}",
                r.0, r.1, r.2
            );
        });

    // try_conn_async()

    println!("Hello, world!");
}
